package com.rub.android.jetpack.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.rub.android.R
import com.rub.android.databinding.ActivityDataBindItemBinding
import com.rub.android.jetpack.model.UserIdol

class RecyclerVidewaAapter : RecyclerView.Adapter<RecyclerVidewaAapter.IViewHolder> {

    var dataList: MutableList<UserIdol>

    constructor(dataList: MutableList<UserIdol>) {
        this.dataList = dataList
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IViewHolder {
        //ActivityDataBindItemBinding is android create  from activity_data_bind_item
        var itemBinding = DataBindingUtil.inflate(
            LayoutInflater.from(parent.context),
            R.layout.activity_data_bind_item,
            parent,
            false
        ) as ActivityDataBindItemBinding

        return IViewHolder(itemBinding)
    }

    override fun onBindViewHolder(holder: IViewHolder, position: Int) {
        var userIdol = dataList[position]
        holder.itemBinding.user = userIdol
    }

    override fun getItemCount(): Int = dataList.size

    class IViewHolder : RecyclerView.ViewHolder {

        val itemBinding: ActivityDataBindItemBinding

        //constructor(view: View) : super(view)

        constructor(itemBinding: ActivityDataBindItemBinding) : super(itemBinding.root) {
            this.itemBinding = itemBinding
        }

    }


}

